﻿$(document).ready(function () {

    $('#cc').calendar({
        onSelect: function (date) {
            $('#calendar').fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate());
        }
    });

    $(document).tooltip();

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    $(document).click(function () {
        $('#calendar').fullCalendar('render');
    });
    var panel = $('.layout').layout('panel', 'west');    // get the west panel
    panel.panel({
        onBeforeCollapse: function () {
            // return false will stop the collapse action
        },
        onCollapse: function () {
            //            alert('after west panel collapsed');
            $('#calendar').fullCalendar('render');
        },
        onExpand: function () {
            //            alert('after west panel expanded');
        },
        onResize: function () {
        }
    });

    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'agendaDay,agendaWeek,month'
        },
        defaultView: 'agendaDay',
        editable: true,
        disableDragging: true,
        events: function (start, end, callback) {
            $.ajax({
                type: "POST",
                url: "/Handler/MyService.asmx/GetEvents",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify({
                    // our hypothetical feed requires UNIX timestamps
                    start: start, // Math.round(start.getTime() / 1000),
                    end: end // Math.round(end.getTime() / 1000)
                }),
                success: function (doc) {
                    var events = [];
                    $.each(doc.d, function () {
                        var jsonDate = this.Start;
                        var jsonDate1 = this.End;
                        events.push({
                            title: this.Title,
                            start: new Date(parseInt(jsonDate.substr(6))), // will be parsed,
                            end: new Date(parseInt(jsonDate1.substr(6))),
                            allDay: this.AllDay,
                            tip: this.Tip,
                            url: this.Url
                        });
                    });
                    callback(events);
                }
            });
        },
        eventRender: function (event, element) {
            element.attr('title', event.tip);
        }
    });

});